<?php
set_time_limit(0);
include_once (PATH_SQL . 'message_sql.php');
include_once (PATH_MODEL . 'message_model.php');
include_once (PATH_VIEW_ADMIN . 'message_view.php');
$oModel_message=new Model_Message();
$oViewMessage = new View_Admin_Message($oModel_message);

$oModel_message->setData('page_size',25);
$oModel_message->setData('pagegroup_size',5);
$oModel_message->setData('stylesheet',"paging");

$sAction=$_REQUEST['sAction'];

switch($sAction) {
    case 'inbox': {
            $oViewMessage->displayMessageInbox($oModel_message);
            $oViewMessage->displayListMessageInbox($oModel_message);
            $oModel_message->unsetData('message_status');
            break;
        }

    case 'outbox': {

            $oViewMessage->displayMessageOutbox($oModel_message);
            $oViewMessage->displayListMessageOutbox($oModel_message);
            $oModel_message->unsetData('message_id');
            break;
        }

    case 'update_status': {
            $oModel_message->unsetData('message_id');
            $oModel_message->unsetData('message_status');

            if (count($_POST['hotel_page_sort'] > 0)) {
                foreach ($_POST['hotel_page_sort'] as $sKey => $sValue) {
                    $oModel_message->setData('message_id', $sKey);
                    $oModel_message->setData('message_status', intval($_POST['message_status'][$sKey]));
                    $oModel_message->updateMessage();
                }
            }
            redir("?sMod=message&sAction=inbox");
        }

    case 'do_add_form': {
            $oViewMessage->displayMessageNew($oModel_message);
            $oViewMessage->displayListUser($oModel_message);
            break;
        }
    case 'do_add_new': {
            $check_insert=$oModel_message->insertMessage();
            if($check_insert) {
                redir('?sMod=message&sAction=outbox&status=input_success');
            }
            else {
                $sErrorMsg =  $oModel_message->aLanguage['ALERT']['form_cannot_submit'] . $sErrorMsg;
                $oModel_message->setErrorMsg($sErrorMsg);
            }
            break;
        }
    case 'do_delete': {
            $id=$_GET['id'];
            $result = $oModel_message->deleteMessage($id);
            if(!$result) {
                if($_GET['from']=='out') {
                    redir('?sMod=message&sAction=outbox&status=delError');
                }
                else
                    redir('?sMod=message&sAction=inbox&status=delError');

            }
            else {	if($_GET['from']=='out') {
                    redir('?sMod=message&sAction=outbox&status=delSuccess');
                }
                else
                    redir('?sMod=message&sAction=inbox&status=delSuccess');
            }
            break;
        }
    case 'view_message': {
            echo $oViewMessage->displayMessageView($oModel_message);
           
            die;
            break;
        }

    case 'message_board': {
            $oViewMessage->displayMessageBoard($oModel_message);
            $oViewMessage->displayListMessageBoard($oModel_message);
            break;
        }
}
$oViewMessage->displayPage($oModel_message);
